<script lang="ts" name="SvgIcon" setup>
import { computed } from "vue";

const props = defineProps({
  prefix: {
    type: String,
    default: "icon",
  },
  name: {
    type: String,
    required: true,
  },
  color: {
    type: String,
    default: "#333",
  },
  size: {
    type: String,
    default: "24",
  },
  class: {
    type: String,
    default: "",
  },
});
const iconName = computed(() => `#icon-${props.name}`);
const svgClass = computed(() => {
  return props.name
    ? `svg-icon icon-${props.name} ${props.class}`
    : `svg-icon ${props.class}`;
});
</script>

<template>
  <svg
    :class="svgClass"
    v-bind="$attrs"
    :style="{ color: color, fontSize: size }"
  >
    <use :xlink:href="iconName" />
  </svg>
</template>

<style lang="less" scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  vertical-align: middle;
  fill: currentColor;
  overflow: hidden;
}
</style>
